
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.8 面向对象的程序设计 · gitbook电子书</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="递归&冒泡&快速.html" />
    
    
    <link rel="prev" href="流程控制&函数.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../使用/使用.html">
            
                <a href="../使用/使用.html">
            
                    
                    md语法 & gitbook使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../面试题/面试题.html">
            
                <a href="../面试题/面试题.html">
            
                    
                    面试题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../面试题/html.html">
            
                <a href="../面试题/html.html">
            
                    
                    HTML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../面试题/css.html">
            
                <a href="../面试题/css.html">
            
                    
                    CSS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../面试题/js.html">
            
                <a href="../面试题/js.html">
            
                    
                    JavaScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../面试题/vue.html">
            
                <a href="../面试题/vue.html">
            
                    
                    Vue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../面试题/小程序.html">
            
                <a href="../面试题/小程序.html">
            
                    
                    小程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../面试题/编程题.html">
            
                <a href="../面试题/编程题.html">
            
                    
                    编程题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../html/">
            
                <a href="../html/">
            
                    
                    1. HTML
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../html/1.常用标签.html">
            
                <a href="../html/1.常用标签.html">
            
                    
                    1.1 常用标签
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../html/2.列表.html">
            
                <a href="../html/2.列表.html">
            
                    
                    1.2 列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../html/3.表单.html">
            
                <a href="../html/3.表单.html">
            
                    
                    1.3 表单属性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../html/4.音频&视频.html">
            
                <a href="../html/4.音频&视频.html">
            
                    
                    1.4 ifame & audio & video
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../css/">
            
                <a href="../css/">
            
                    
                    2. CSS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../css/1.选择器.html">
            
                <a href="../css/1.选择器.html">
            
                    
                    2.1 选择器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../css/2.字体样式.html">
            
                <a href="../css/2.字体样式.html">
            
                    
                    2.2 字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../css/3.背景.html">
            
                <a href="../css/3.背景.html">
            
                    
                    2.3 背景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../css/4.盒子模型.html">
            
                <a href="../css/4.盒子模型.html">
            
                    
                    2.4 盒子模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../css/5.浮动.html">
            
                <a href="../css/5.浮动.html">
            
                    
                    2.5 浮动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../css/6.定位和渐变.html">
            
                <a href="../css/6.定位和渐变.html">
            
                    
                    2.6 定位 & 渐变
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../css/7.过渡&变形.html">
            
                <a href="../css/7.过渡&变形.html">
            
                    
                    2.7 过渡 & 变形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../css/8.动画.html">
            
                <a href="../css/8.动画.html">
            
                    
                    2.8 动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../css/9.滤镜.html">
            
                <a href="../css/9.滤镜.html">
            
                    
                    2.9 滤镜
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../css/10.布局.html">
            
                <a href="../css/10.布局.html">
            
                    
                    2.10 布局
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    3. JS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="数据类型.html">
            
                <a href="数据类型.html">
            
                    
                    3.1 数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="语句.html">
            
                <a href="语句.html">
            
                    
                    操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="操作符.html">
            
                <a href="操作符.html">
            
                    
                    语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="基本类型和引用类型的值.html">
            
                <a href="基本类型和引用类型的值.html">
            
                    
                    基本类型和引用类型的值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="执行环境及作用域.html">
            
                <a href="执行环境及作用域.html">
            
                    
                    执行环境及作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="垃圾收集.html">
            
                <a href="垃圾收集.html">
            
                    
                    垃圾收集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="Object类型.html">
            
                <a href="Object类型.html">
            
                    
                    Object类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="Array类型.html">
            
                <a href="Array类型.html">
            
                    
                    Array类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="Date类型.html">
            
                <a href="Date类型.html">
            
                    
                    Date类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="string&array.html">
            
                <a href="string&array.html">
            
                    
                    3.2 String & Array
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="date.html">
            
                <a href="date.html">
            
                    
                    3.3 Date类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="正则表达式.html">
            
                <a href="正则表达式.html">
            
                    
                    3.4 RegExp类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.14" data-path="global&math.html">
            
                <a href="global&math.html">
            
                    
                    3.5 Global对象 & Math对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.15" data-path="变量&作用域&垃圾收集.html">
            
                <a href="变量&作用域&垃圾收集.html">
            
                    
                    3.6 变量 & 作用域 & 垃圾收集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.16" data-path="流程控制&函数.html">
            
                <a href="流程控制&函数.html">
            
                    
                    3.7 流程控制 & 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.17" data-path="面向对象.html">
            
                <a href="面向对象.html">
            
                    
                    3.8 面向对象的程序设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.18" data-path="递归&冒泡&快速.html">
            
                <a href="递归&冒泡&快速.html">
            
                    
                    3.9 递归 & 冒泡 & 快速
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.19" data-path="定时器&防抖&节流.html">
            
                <a href="定时器&防抖&节流.html">
            
                    
                    3.10 定时器\防抖\节流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.20" data-path="DOM获取&DOM操作.html">
            
                <a href="DOM获取&DOM操作.html">
            
                    
                    3.11 DOM获取 & DOM操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.21" data-path="键盘事件&鼠标事件.html">
            
                <a href="键盘事件&鼠标事件.html">
            
                    
                    3.12 键盘事件 & 鼠标事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.22" data-path="事件冒泡&事件代理&事件绑定.html">
            
                <a href="事件冒泡&事件代理&事件绑定.html">
            
                    
                    3.13 事件冒泡\代理\绑定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.23" data-path="this指向.html">
            
                <a href="this指向.html">
            
                    
                    3.14 this指向
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.24" data-path="Ajax&跨域.html">
            
                <a href="Ajax&跨域.html">
            
                    
                    3.15 Ajax & 跨域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.25" data-path="Bom.html">
            
                <a href="Bom.html">
            
                    
                    3.16 BOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.26" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    3.17 ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.27" data-path="js实例.html">
            
                <a href="js实例.html">
            
                    
                    3.18 js实例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    4. Vue
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../vue/1.基础.html">
            
                <a href="../vue/1.基础.html">
            
                    
                    4.1 基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../vue/2.生命周期.html">
            
                <a href="../vue/2.生命周期.html">
            
                    
                    4.2 生命周期
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../vue/3.vuex.html">
            
                <a href="../vue/3.vuex.html">
            
                    
                    4.3 vuex
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../vue/4.原理.html">
            
                <a href="../vue/4.原理.html">
            
                    
                    4.4 深入响应式原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../vue/5.组件.html">
            
                <a href="../vue/5.组件.html">
            
                    
                    4.5 组件进阶
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../vue/6.规模化.html">
            
                <a href="../vue/6.规模化.html">
            
                    
                    4.6 规模化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../vue/7.过渡&动画.html">
            
                <a href="../vue/7.过渡&动画.html">
            
                    
                    4.7 过渡 & 动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../vue/8.可复用性&组合.html">
            
                <a href="../vue/8.可复用性&组合.html">
            
                    
                    4.8 可复用性 & 组合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../vue/9.工具.html">
            
                <a href="../vue/9.工具.html">
            
                    
                    4.9 工具
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../Node/">
            
                <a href="../Node/">
            
                    
                    5. Node
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../插件/">
            
                <a href="../插件/">
            
                    
                    插件
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3.8 面向对象的程序设计</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5BF9;&#x8C61;&#x521B;&#x5EFA;">&#x5BF9;&#x8C61;&#x521B;&#x5EFA;</h1>
<h3 id="1-&#x6784;&#x9020;&#x51FD;&#x6570;">1. &#x6784;&#x9020;&#x51FD;&#x6570;</h3>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> person = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
    person.name = <span class="hljs-string">&quot;object&quot;</span>;
    person.age = <span class="hljs-number">18</span>;
</code></pre>
<h3 id="2-&#x5B57;&#x9762;&#x91CF;&#x521B;&#x5EFA;">2. &#x5B57;&#x9762;&#x91CF;&#x521B;&#x5EFA;</h3>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> obj1 = {
        name:<span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>,
        age:<span class="hljs-string">&quot;18&quot;</span>
    }
</code></pre>
<pre><code class="lang-js">    <span class="hljs-comment">//&#x5DE5;&#x5382;&#x6A21;&#x5F0F;&#x7684;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;&#xFF08;&#x51FD;&#x6570;&#xFF09;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">factory</span>(<span class="hljs-params">name,age</span>)</span>{
        <span class="hljs-keyword">var</span> obj2 = {
            <span class="hljs-string">&quot;name&quot;</span>:name,
            <span class="hljs-string">&quot;age&quot;</span>:age
        }
        <span class="hljs-comment">//ES6 key&#x548C;value&#x76F8;&#x540C;&#x540D;&#x79F0;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x5FFD;&#x7565;value</span>
        <span class="hljs-keyword">return</span> {
            name,
            age
        }
    }

    <span class="hljs-comment">//&#x5DE5;&#x5382;&#x51FD;&#x6570;&#x7684;&#x7F3A;&#x70B9;&#xFF1A;&#x65E0;&#x6CD5;&#x901A;&#x8FC7;&#x65B9;&#x6CD5;&#x6765;&#x83B7;&#x77E5;&#x5BF9;&#x8C61;&#x7684;&#x6765;&#x6E90;</span>
    <span class="hljs-keyword">var</span> obj2 = factory(<span class="hljs-string">&quot;&#x5382;&#x59B9;&quot;</span>,<span class="hljs-number">18</span>)
    <span class="hljs-built_in">console</span>.log(obj2 <span class="hljs-keyword">instanceof</span> factory)

    <span class="hljs-comment">//&#x901A;&#x8FC7;new&#x64CD;&#x4F5C;&#x7B26;  &#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61; &#x53EF;&#x77E5;&#x5BF9;&#x8C61;&#x6765;&#x6E90;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;</span>
    <span class="hljs-comment">//&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E00;&#x822C;&#x4EE5;&#x5927;&#x9A7C;&#x5CF0;&#x6CD5;&#x547D;&#x540D;</span>
    <span class="hljs-keyword">var</span> obj3 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
    <span class="hljs-built_in">console</span>.log(obj3 <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span>)

    <span class="hljs-comment">//object.create()&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x4F5C;&#x7EE7;&#x627F;</span>
    <span class="hljs-comment">//obj&#x4E3A;null&#xFF0C;&#x521B;&#x5EFA;&#x51FA;&#x6765;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5B8C;&#x5168;&#x7A7A;&#x7684;&#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">var</span> obj4 = <span class="hljs-built_in">Object</span>.create(<span class="hljs-built_in">Object</span>.prototype);
    <span class="hljs-built_in">console</span>.log(obj4 <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span>)

    <span class="hljs-comment">/*********  &#x5BF9;&#x8C61;&#x5C5E;&#x6027;  *********/</span>
    <span class="hljs-keyword">var</span> obj5 = {
        name:<span class="hljs-string">&quot;&#x738B;&#x4E94;&quot;</span>,
    }
    obj5.age = <span class="hljs-number">19</span>     <span class="hljs-comment">//&#x5BF9;&#x8C61;.&#x5C5E;&#x6027; = &#x503C;</span>
    obj5[<span class="hljs-string">&quot;sex&quot;</span>] = <span class="hljs-string">&quot;male&quot;</span>;   <span class="hljs-comment">//&#x5BF9;&#x8C61;[&quot;&#x5C5E;&#x6027;&#x540D;&#x5B57;&#x7B26;&#x4E32;&quot;]</span>

    <span class="hljs-built_in">Object</span>.defineProperty(obj5,<span class="hljs-string">&quot;tall&quot;</span>,{
        value:<span class="hljs-number">180</span>,    <span class="hljs-comment">//&#x503C;</span>
        <span class="hljs-comment">//&#x53EF;&#x679A;&#x4E3E;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;false&#xFF0C;&#x4E3A;true&#x65F6;&#x624D;&#x80FD;&#x88AB;in&#x64CD;&#x4F5C;&#x7B26;&#x5339;&#x914D;&#x51FA;&#x6765;</span>
        enumerable:<span class="hljs-literal">true</span>  ,
        <span class="hljs-comment">//&#x53EF;&#x6539;&#x5199; &#x9ED8;&#x8BA4;&#x4E3A;true</span>
        writable:<span class="hljs-literal">false</span>,
        <span class="hljs-comment">//&#x53EF;&#x88AB;&#x64CD;&#x4F5C;&#x7B26;&#x63A7;&#x5236;&#xFF08;delete&#xFF09;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;false</span>
        configurable:<span class="hljs-literal">true</span>,
    })

    <span class="hljs-comment">//in &#x64CD;&#x4F5C;&#x7B26;  &#x5339;&#x914D;&#x53EF;&#x679A;&#x4E3E;&#x5C5E;&#x6027;</span>
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> k <span class="hljs-keyword">in</span> obj5){
    <span class="hljs-built_in">console</span>.log( k,<span class="hljs-string">&quot;:&quot;</span>,obj5[k] )
    }
    <span class="hljs-built_in">console</span>.log(obj5)

    <span class="hljs-comment">//ES6 for..of&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x904D;&#x5386;&#x51FA;value</span>
    <span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]
    <span class="hljs-keyword">for</span>( <span class="hljs-keyword">var</span> v <span class="hljs-keyword">of</span> arr){
    <span class="hljs-built_in">console</span>.log(v)
    }

    <span class="hljs-built_in">Object</span>.defineProperty(obj5,<span class="hljs-string">&quot;weight&quot;</span>,{
        <span class="hljs-comment">//              value:150,</span>
        enumerable:<span class="hljs-literal">true</span>,
        <span class="hljs-comment">//              writable:true,</span>
        configurable:<span class="hljs-literal">true</span>,
        <span class="hljs-comment">//&#x5C5E;&#x6027;&#x88AB;&#x8BBF;&#x95EE;&#x65F6;&#xFF0C;&#x6267;&#x884C;&#x7684;&#x56DE;&#x8C03;</span>
        <span class="hljs-comment">//&#x6BCF;&#x6B21;&#x8BBF;&#x95EE;&#x91CD;&#x65B0;&#x8BA1;&#x7B97;&#xFF0C;&#x53EF;&#x4EE5;&#x5199;&#x4E00;&#x4E9B;&#x52A8;&#x6001;&#x7684;&#x503C;&#x968F;&#x67D0;&#x79CD;&#x6761;&#x4EF6;&#x53D8;&#x5316;</span>
        get : <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x770B;&#x6211;&#x4F53;&#x91CD;?&quot;</span>)
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.tall*<span class="hljs-number">1.1</span>;
        },
        <span class="hljs-comment">//&#x5F53;&#x5C5E;&#x6027;&#x88AB;&#x8D4B;&#x503C;&#x64CD;&#x4F5C;&#x4E4B;&#x540E;&#xFF0C;&#x6267;&#x884C;&#x56DE;&#x8C03;</span>
        set:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">newValue</span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;set&quot;</span>,newValue)
            <span class="hljs-comment">//&#x4E0D;&#x8981;&#x5728;set&#x91CC;&#x9762;&#x8FDB;&#x884C;&#x5BF9;&#x540C;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x8D4B;&#x503C;&#x64CD;&#x4F5C;&#xFF0C;&#x4F1A;&#x5F15;&#x8D77;&#x6B7B;&#x5FAA;&#x73AF;</span>
            <span class="hljs-comment">//this.weight = newVaule</span>
        }
    })


    <span class="hljs-comment">//object.defineProperty&#x7684;&#x590D;&#x6570;&#x5F62;&#x5F0F;&#xFF0C;&#x540C;&#x65F6;&#x8BBE;&#x7F6E;&#x591A;&#x4E2A;&#x5C5E;&#x6027;</span>
    <span class="hljs-built_in">Object</span>.defineProperties(obj5,{
    <span class="hljs-string">&quot;job&quot;</span>:{
        value:<span class="hljs-string">&quot;&#x4FDD;&#x6D01;&quot;</span>
    },
    <span class="hljs-string">&quot;hobby&quot;</span>:{
        value:[<span class="hljs-string">&quot;fishing&quot;</span>,<span class="hljs-string">&quot;swimming&quot;</span>]
    }
    })
    <span class="hljs-built_in">console</span>.log(obj5)
</code></pre>
<h1 id="&#x6784;&#x9020;&#x51FD;&#x6570;&#x548C;&#x539F;&#x578B;&#x5BF9;&#x8C61;">&#x6784;&#x9020;&#x51FD;&#x6570;&#x548C;&#x539F;&#x578B;&#x5BF9;&#x8C61;</h1>
<pre><code class="lang-js">    <span class="hljs-comment">//&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">var</span> obj1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();
    <span class="hljs-keyword">var</span> num1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Number</span>();
    <span class="hljs-keyword">var</span> arr1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>();

    <span class="hljs-comment">/*****
    * &#x51FD;&#x6570;&#x58F0;&#x660E;&#x540E;&#xFF0C;&#x5C31;&#x4F1A;&#x81EA;&#x52A8;&#x6709;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x7684;&#x539F;&#x578B;&#xFF08;prototype&#xFF09;&#xFF0C;
    * &#x5B9E;&#x4F8B;&#x5316;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8FD9;&#x4E9B;&#x539F;&#x578B;&#x5BF9;&#x8C61;_proto_&#x8BBF;&#x95EE;&#x8FD9;&#x4E9B;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x548C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E0A;&#x7684;&#x65B9;&#x6CD5;
    * 
    * &#x539F;&#x578B;&#x5BF9;&#x8C61;&#xFF1A;constructor&#x5C5E;&#x6027;&#x6307;&#x7684;&#x662F;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;_proto_&#x6307;&#x5411;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#xFF08;&#x4FD7;&#x79F0;&#x539F;&#x578B;&#x94FE;&#xFF09;
    * [[prototype]]
    * ******/</span>

    <span class="hljs-comment">//&#x6784;&#x9020;&#x51FD;&#x6570;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Car</span>(<span class="hljs-params">type,run</span>)</span>{
        <span class="hljs-keyword">this</span>.type = type;<span class="hljs-comment">//&#x5B9E;&#x4F8B;&#x5316;&#x540E;&#x7684;&#x5BF9;&#x8C61;&#x4E0A;&#x7684;&#x5C5E;&#x6027;</span>

        <span class="hljs-comment">//&#x6784;&#x9020;&#x51FD;&#x6570;&#x91CC;&#x7684;this&#x7684;&#x5C5E;&#x6027;&#x90FD;&#x662F;&#x653E;&#x5728;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x91CC;&#x7684;&#xFF08;&#x72EC;&#x7ACB;&#xFF09;</span>
        <span class="hljs-keyword">this</span>.run = run;
        <span class="hljs-comment">//&#x5148;&#x83B7;&#x53D6;&#x516C;&#x5171;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x518D;&#x53BB;&#x4FEE;&#x6539;</span>
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.run())

    }
    <span class="hljs-comment">//Car.prototype&#x539F;&#x578B;&#x5BF9;&#x8C61;</span>
    <span class="hljs-comment">//Car.prototype&#x4E0A;&#x7684;&#x5C5E;&#x6027;&#x90FD;&#x662F;&#x5171;&#x4EAB;</span>
    Car.prototype.run = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;run&quot;</span>)
    }

    <span class="hljs-keyword">var</span> c1 = <span class="hljs-keyword">new</span> Car(<span class="hljs-string">&quot;&#x706B;&#x8F66;&quot;</span>)

    <span class="hljs-keyword">var</span> c2 = <span class="hljs-keyword">new</span> Car(<span class="hljs-string">&quot;&#x8D27;&#x8F66;&quot;</span>)



    <span class="hljs-comment">//            console.log(c1 instanceof Car);//true</span>
    <span class="hljs-built_in">console</span>.log(c1,c2);<span class="hljs-comment">//true</span>
</code></pre>
<h1 id="&#x7EE7;&#x627F;">&#x7EE7;&#x627F;</h1>
<pre><code class="lang-javascript">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Father</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">this</span>.name = <span class="hljs-string">&quot;&#x7236;&#x4EB2;&quot;</span>
        <span class="hljs-keyword">this</span>.eat = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x5403;&#x5403;&#x5403;&quot;</span>)
        }
    }
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Son</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">this</span>.name = <span class="hljs-string">&quot;&#x513F;&#x5B50;&quot;</span>
        <span class="hljs-keyword">this</span>.newSkill = [<span class="hljs-string">&quot;Es6&quot;</span>]
    }

    <span class="hljs-keyword">var</span> f1 = <span class="hljs-keyword">new</span> Father();
    <span class="hljs-comment">//&#x5B50;&#x7C7B;&#x7684;&#x539F;&#x578B;&#x5C31;&#x662F;&#x7236;&#x7C7B;&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;</span>
    Son.prototype = f1;
    Son.prototype.constructor = Son;

    <span class="hljs-keyword">var</span> s1 = <span class="hljs-keyword">new</span> Son();

    <span class="hljs-built_in">console</span>.log(f1,s1)

    <span class="hljs-comment">//Object.create(&#x88AB;&#x7EE7;&#x627F;&#x7684;&#x5BF9;&#x8C61;)</span>
    <span class="hljs-keyword">var</span> s2 = <span class="hljs-built_in">Object</span>.create(f1);
    <span class="hljs-built_in">console</span>.log(s2,<span class="hljs-built_in">Object</span>.create(<span class="hljs-literal">null</span>));

    Father.prototype.skill = [<span class="hljs-string">&quot;html&quot;</span>,<span class="hljs-string">&quot;css&quot;</span>,<span class="hljs-string">&quot;js&quot;</span>];
    <span class="hljs-comment">//hasOwnProperty&#x5224;&#x65AD;&#x5BF9;&#x8C61;&#x4E0A;&#x7684;&#x5C5E;&#x6027;&#x662F;&#x4E0D;&#x662F;&#x5BF9;&#x8C61;&#x81EA;&#x5DF1;&#x62E5;&#x6709;&#x7684;&#x5C5E;&#x6027;</span>
    <span class="hljs-built_in">console</span>.log(s1.hasOwnProperty(<span class="hljs-string">&quot;newSkill&quot;</span>))
    <span class="hljs-comment">//isPrototypeof &#x5224;&#x65AD;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x548C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x7CFB;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;isPrototypeOf&quot;</span>,Son.prototype.isPrototypeOf(s1))
    <span class="hljs-comment">//getPrototypeOf &#x8FD4;&#x56DE;&#x539F;&#x578B;&#x5BF9;&#x8C61;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;getPrototypeOf&quot;</span>,<span class="hljs-built_in">Object</span>.getPrototypeOf(s1)==Son.prototype);

    <span class="hljs-keyword">var</span> obj5 = {
        name:<span class="hljs-string">&quot;five&quot;</span>
    }
    <span class="hljs-comment">//&#x963B;&#x6B62;&#x5BF9;&#x8C61;&#x8FDB;&#x884C;&#x6269;&#x5C55;</span>
    <span class="hljs-built_in">Object</span>.preventExtensions(obj5);
    obj5.age = <span class="hljs-number">18</span>;   <span class="hljs-comment">//&#x4E0D;&#x53EF;&#x4EE5;</span>
    obj5.name=<span class="hljs-string">&quot;evif&quot;</span> <span class="hljs-comment">//&#x53EF;&#x4EE5;</span>
    <span class="hljs-keyword">delete</span> obj5.name; <span class="hljs-comment">//&#x53EF;&#x4EE5;</span>
    <span class="hljs-built_in">console</span>.log(obj5)

    <span class="hljs-comment">//&#x5BC6;&#x5C01; &#x963B;&#x6B62;&#x6269;&#x5C55;&#x5E76;&#x4E14;&#x7981;&#x6B62;&#x64CD;&#x4F5C;&#x7B26;</span>
    <span class="hljs-keyword">var</span> obj6 = {
        name:<span class="hljs-string">&quot;six&quot;</span>
    }
    <span class="hljs-built_in">Object</span>.seal(obj6);
    obj6.name = <span class="hljs-string">&quot;xis&quot;</span>;
    <span class="hljs-keyword">delete</span> obj6.name;
    <span class="hljs-built_in">console</span>.log(obj6);


    <span class="hljs-comment">//&#x51BB;&#x7ED3; &#x5728;seal&#xFF08;&#xFF09;&#x57FA;&#x7840;&#x4E0A;&#xFF0C;&#x7981;&#x6B62;&#x5BF9;&#x5C5E;&#x6027;&#x503C;&#x7684;&#x4FEE;&#x6539;</span>
    <span class="hljs-keyword">var</span> obj7={
        name:<span class="hljs-string">&quot;seven&quot;</span>
    }
    <span class="hljs-built_in">Object</span>.freeze(obj7);
    obj7.name = <span class="hljs-string">&quot;neves&quot;</span>;
    <span class="hljs-built_in">console</span>.log(obj7);


    <span class="hljs-comment">//&#x83B7;&#x53D6;&#x5C5E;&#x6027;&#x540D;&#xFF08;key&#xFF09;</span>
    <span class="hljs-keyword">var</span> obj8 ={
        name:<span class="hljs-string">&quot;eight&quot;</span>,
        age:<span class="hljs-number">8</span>
    }
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">Object</span>.keys(obj8))
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="流程控制&函数.html" class="navigation navigation-prev " aria-label="Previous page: 3.7 流程控制 & 函数">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="递归&冒泡&快速.html" class="navigation navigation-next " aria-label="Next page: 3.9 递归 & 冒泡 & 快速">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.8 面向对象的程序设计","level":"1.5.17","depth":2,"next":{"title":"3.9 递归 & 冒泡 & 快速","level":"1.5.18","depth":2,"path":"JS/递归&冒泡&快速.md","ref":"JS/递归&冒泡&快速.md","articles":[]},"previous":{"title":"3.7 流程控制 & 函数","level":"1.5.16","depth":2,"path":"JS/流程控制&函数.md","ref":"JS/流程控制&函数.md","articles":[]},"dir":"ltr"},"config":{"plugins":["toggle-chapters","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"toggle-chapters":{},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"gitbook电子书","gitbook":"*","description":"记录前端相关的知识点以及一些示例的demo"},"file":{"path":"JS/面向对象.md","mtime":"2019-03-22T03:14:49.942Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-09-06T08:37:43.293Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

